#include "main_window.h"
#include <QWidget>
#include <QHBoxLayout>
#include <QPushButton>
#include <message_view.h>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    this->resize(800, 600);
    this->setWindowTitle("message demo");
    auto *centralWidget = new QWidget(this);
    this->setCentralWidget(centralWidget);
    auto *btnLayout = new QHBoxLayout(centralWidget);
    auto *btn1      = new QPushButton("seccuss", this);
    auto *btn2      = new QPushButton("warning", this);
    auto *btn3      = new QPushButton("error", this);
    auto *btn4      = new QPushButton("info", this);
    btnLayout->addWidget(btn1);
    btnLayout->addWidget(btn2);
    btnLayout->addWidget(btn3);
    btnLayout->addWidget(btn4);
    // btn->setGeometry(300, 500, 120, 50);
    MessageView *message = new MessageView(this);
    // message->setGeometry(0, 0, 800, 300);

    QObject::connect(btn1, &QPushButton::clicked, this, [message](){
        message->send("seccuss", MessgeType::seccuss);
    });

    QObject::connect(btn2, &QPushButton::clicked, this, [message](){
        message->send("warning", MessgeType::warning);
    });

    QObject::connect(btn3, &QPushButton::clicked, this, [message](){
        message->send("error", MessgeType::error, 5000);
    });

    QObject::connect(btn4, &QPushButton::clicked, this, [message](){
        message->send("info", MessgeType::info, 0);
    });
}

MainWindow::~MainWindow()
{
}
